<?php
session_start();

$user = $_POST['login'];
$pin = $_POST['password'];

include 'dbconnect.php';

  // Check connection
if (mysqli_connect_errno())
  {
  //echo "alert'Failed to connect to MySQL: ' . mysqli_connect_error()";
  }

$result = mysqli_query($con,"SELECT * FROM connections");

$error = 0;

while($row = mysqli_fetch_array($result))
  {
  if ($row['email']==$user && $row['password']==$pin){
    $error = 1;
    //session varables
    $_SESSION['wid']=$row['id'];
    $_SESSION['email']=$row['email'];
    $_SESSION['number']=$row['phoneNumber'];
    $_SESSION['display']=$row['displayName'];
    ?>
    <script type="text/javascript">
		window.location.href = '../';
	</script>
	<?php
    //echo "<script type='text/javascript'>"."alert('Welcome ". $_SESSION['fname']. " ". $_SESSION['lname'] . "');"."</script>";
    //echo "Welcome ". $_SESSION['fname']. " ". $_SESSION['lname']. " ". $_SESSION['email']. " ". $_SESSION['phone']. " ". $_SESSION['admin']. " ". $_SESSION['username']. " ". $_SESSION['phoneId'];
    break;
  }
  }
  
  if ($error != 1){
	$_SESSION['error']="Incorrect email or password.";
  ?>
    <script type="text/javascript">
		window.location.href = '../../';
	</script>
<?php
  }
  
mysqli_close($con);
?>
